package com.bnlr.nohttp;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;

import com.yolanda.nohttp.R;

import java.io.IOException;

import pl.droidsonroids.gif.GifDrawable;
import pl.droidsonroids.gif.GifImageView;

/**
 * Created by hp on 2017/11/7.
 */

public class LoadingDialog extends Dialog {

    Context context;
    private GifImageView iv_frame;
    private GifDrawable gifDrawable;
    // private AnimationDrawable frameAnim;

    public LoadingDialog(Context context) {
        super(context);
        this.context = context;
    }

    public LoadingDialog(Context context, int theme){
        super(context, theme);
        this.context = context;
    }
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.setContentView(R.layout.dialog_loading);
        iv_frame=(GifImageView)findViewById(R.id.iv_frame);
       // frameAnim=(AnimationDrawable)context.getResources().getDrawable(R.drawable.bullet_anim);
        //iv_frame.setBackgroundDrawable(frameAnim);
       // start();
        try {
            gifDrawable = new GifDrawable(context.getResources(), R.drawable.car_loading);
            // gif1加载一个动态图gif
            iv_frame.setImageDrawable(gifDrawable);
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

   /* protected void start() {
        if (frameAnim != null && !frameAnim.isRunning()) {
            frameAnim.start();
        }
    }
*/
    @Override
    public void dismiss() {
        super.dismiss();
        if (gifDrawable != null) {
            gifDrawable.stop();
        }
    }

   /* protected void stop() {
        if (frameAnim != null && !frameAnim.isRunning()) {
            frameAnim.stop();
        }
    }*/
}
